using System.Collections.Generic;
using System.Threading.Tasks;
using Godot;

namespace Box {
    public partial class ProcessTree : Node {
        public Dictionary<string,bool> Status = new Dictionary<string, bool>();
        public List<IUpdateNode> UpdateNodes = new List<IUpdateNode>();
        public ProcessNodeRoot Root;
        public double ProcessTickTime = 0.2;
        public double ProcessTickTimer = 0;

        public void AddStatus(string status) {
            Status[status] = true;
        }

        public void RemoveStatus(string status) {
            Status[status] = false;
        }

        public bool HasStatus(string status) {
            if(!Status.ContainsKey(status)) {
                Status[status] = false;
            }
            return Status[status];
        }

        public void TryAddToUpdate(ProcessNode node) {
            if(node is IUpdateNode) {
                UpdateNodes.Add(node as IUpdateNode);
            }
        }

        public override void _Process(double delta)
        {
            ProcessTickTimer += delta;
            if(ProcessTickTimer >= ProcessTickTime) {
                ProcessTickTimer = 0;
                Root.Output("Output",ProcessTreeNodePortStatus.High);
                Root.Output("Output",ProcessTreeNodePortStatus.Low);
            }
            foreach(IUpdateNode node in UpdateNodes) {
                node.onUpdate(delta);
            }
        }
    }
}